/*
*	(*^。^*) TFrameWork License (*^。^*)
*/

/*
 *  Title :  
 *          
 *  Description :  
 *          
 *          
 *  Date : 
 *
 *  Author : DengPing
 *
 *  Modify : 
 */
using UnityEditor;
using UnityEngine;

namespace TFrameWork.Module.ActionEditor
{
    internal partial class ActionEditor
    {
        
        private ActionData _actionData;

        public ActionData ActionData
        {
            get => _actionData;
        }

        public void InitData()
        {
            if (_actionData != null)
            {
                ActionDataObjectField.value = _actionData;
                CurrentFrameCount = _actionData.FrameCount;
                
                CurrentFrameRate.value = _actionData.FrameRote;
                DataName.value = _actionData.SkillName;
            }
            else
            {
                CurrentFrameCount = 100;
            }

            CurrentSelectFrameIndex = 0;
        }
        
        public void SaveConfig()
        {
            if (_actionData != null)
            {
                _actionData.Sort();
                EditorUtility.SetDirty(_actionData);
                AssetDatabase.SaveAssetIfDirty(_actionData);
                ResetTrackData();
            }
        }

        private void ResetTrackData()
        {
            // 重新引用一下数据
            for (int i = 0; i < trackList.Count; i++)
            {
                trackList[i].OnConfigChanged();
            }
        }

        private void CreateNewActionData()
        {
            
            ActionData newActionData = ScriptableObject.CreateInstance<ActionData>();
            string path = EditorUtility.SaveFilePanelInProject("Save ActionData", "New ActionData", "asset", "请输入要保存的文件名称，并指定路径");
            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            AssetDatabase.CreateAsset(newActionData, path);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            ActionDataObjectField.value = newActionData;
        }
    }
}
